package com.ming.sps.server.bean;

import org.apache.commons.lang.ObjectUtils;

import java.util.HashMap;
import java.util.List;



public class ParamMap extends HashMap<String, Object> {
	

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public Object get(Object key) {
		
		if(key == null){
			return "";
		}
		
		Object obj = super.get(key);
		if(obj == null){
			return "";
		}
		
		return obj;
	}
	
	
	public String getString(Object key) {
		return ObjectUtils.toString(super.get(key)).trim();
	}
	
	public Double getDouble(String key){
		
		if(!isExist(key)){
			return 0.0;
		}
		
		return Double.valueOf(getString(key));
	}
	
	public void clearValue(String key){
		this.put(key, "");
	}
	
	public Boolean isExist(String key){
		String val = getString(key);
		if("".equals(val)){
			return false;
		}
		return true;
	}
	
	public Integer getInteger(String key) {
		
		if(!isExist(key)){
			return 0;
		}
		
		return Integer.parseInt(getString(key));
	}
	
	public long getLong(String key) {
		
		if(!isExist(key)){
			return 0L;
		}
		
		return Long.parseLong(getString(key));
	}
	
	public ParamMap getParamMap(String key) {
		return (ParamMap) super.get(key);
	}
	
	public List<ParamMap> getParamListMap(String key) {
		return (List<ParamMap>) super.get(key);
	}

    public Boolean flag(){
        String key = "flag";
        if(!isExist(key)){
			return false;
		}else{
			return (Boolean) super.get(key);
		}
    }
	
}
